home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / os2 / os2cl015.zip / pmgpi.cpp < prev    next >
C/C++ Source or Header  |  1995-11-24  |  7KB  |  282 lines

  1. /* 
  2.  
  3.  
  4.     pmgpi.cpp (emx+gcc) 
  5.  
  6.     1995 Giovanni Iachello
  7.     This is freeware software. You can use or modify it as you wish,
  8.     provided that the part of code that I wrote remains freeware.
  9.     Freeware means that the source code must be available on request 
  10.     to anyone.
  11.     You must also include this notice in all files derived from this
  12.     file.
  13.  
  14.  
  15. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19.  
  20. #include "pmwin.h"
  21. #include "pmgpi.h"
  22. #include "pmstdres.h"
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25.  
  26.  
  27. PMLogFont::PMLogFont(PMPresSpace& ps,PCCH szFacename, LONG lMaxBaselineExt, LONG lAveCharWidth, USHORT usCodePage)
  28. {
  29.     lLcid=ps.lFontIdcount;
  30.     ps.lFontIdcount++;
  31.     fat.usRecordLength = sizeof(FATTRS); /* sets size of structure   */
  32.     fat.fsSelection = 0;         /* uses default selection           */
  33.     fat.lMatch = 0L;             /* does not force match             */
  34.     fat.idRegistry = 0;          /* uses default registry            */
  35.     fat.usCodePage = usCodePage;        
  36.     fat.lMaxBaselineExt = lMaxBaselineExt;   
  37.     fat.lAveCharWidth = lAveCharWidth;     
  38.     fat.fsType = 0;              /* uses default type                */
  39.     fat.fsFontUse = FATTR_FONTUSE_NOMIX;/* doesn't mix with graphics */
  40.  
  41.     strcpy(fat.szFacename ,szFacename);
  42.  
  43.     ps.createLogFont(NULL, lLcid, &fat);      
  44. }
  45.  
  46. PMLogFont::PMLogFont(PMPresSpace& ps,PFATTRS pfAttrs)
  47. {
  48.     lLcid=ps.lFontIdcount;
  49.     ps.lFontIdcount++;
  50.     fat=*pfAttrs;
  51.     
  52.     ps.createLogFont(NULL, lLcid, &fat);      
  53. }
  54.  
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57.  
  58. PMMenu::PMMenu()
  59. {
  60. }
  61.  
  62. PMMenu::PMMenu(PMWin* iwin)
  63. {
  64.     win=iwin;
  65.     menu=WinWindowFromID(win->getHwnd(),FID_MENU);
  66. }
  67.  
  68. PMMenu::PMMenu(HWND imenu)
  69. {
  70.     menu=imenu;
  71.     win=NULL;
  72. }
  73.  
  74. PMSystemMenu::PMSystemMenu(PMWin* iwin)
  75. {
  76.     win=iwin;
  77.     menu=WinWindowFromID(win->getHwnd(),FID_SYSMENU);
  78. }
  79.  
  80. PMPopupMenu::PMPopupMenu(PMWin* iwin,ULONG idres) 
  81. {
  82.     win=iwin;
  83.     menu=WinLoadMenu(win->getHwnd(),NULLHANDLE,idres);
  84. }
  85.  
  86. BOOL PMPopupMenu::popup(PMPoint& pt,ULONG sel,ULONG flags) 
  87. {
  88.     return WinPopupMenu(win->getHwnd(),win->getHwnd(),menu,pt.x,pt.y,sel,flags);
  89. }
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92.  
  93. PMRect& PMRect::operator = (PMWin* w) 
  94. {
  95.     WinQueryWindowRect (w->getHwnd(), this);
  96.     return *this;
  97. }
  98.  
  99. ////////////////////////////////////////////////////////////////////////////
  100.  
  101.  
  102. PMPresSpace::PMPresSpace(PMDeviceContext* dc,LONG width,LONG height,LONG flOptions,HAB hab)
  103. {
  104.     lFontIdcount=1L;
  105.     SIZEL sizl;
  106.     sizl.cx = width;
  107.     sizl.cy = height;
  108.     hps = GpiCreatePS(hab,*dc,&sizl,flOptions);
  109. }
  110.  
  111. PMPresSpace::~PMPresSpace()
  112. {
  113.     GpiAssociate(hps,NULLHANDLE);
  114.     GpiDestroyPS(hps);        
  115. }
  116.  
  117. BOOL PMPresSpace::queryTextBox (PSZ pszString, LONG lCount2, PPOINTL aptlPoints)
  118. {
  119.     GpiQueryTextBox ( hps, strlen(pszString), (PCH) pszString , lCount2, aptlPoints);
  120. }
  121.  
  122. LONG PMPresSpace::queryTextBoxWidth (PSZ pszString)
  123. {
  124.     POINTL aptlPoints[TXTBOX_COUNT];
  125.     GpiQueryTextBox ( hps, strlen(pszString), (PCH) pszString , TXTBOX_COUNT, aptlPoints);
  126.     return aptlPoints[TXTBOX_TOPRIGHT].x;
  127. }
  128.  
  129. LONG PMPresSpace::queryTextBoxHeight (PSZ pszString)
  130. {
  131.     POINTL aptlPoints[TXTBOX_COUNT];
  132.     GpiQueryTextBox ( hps, strlen(pszString), (PCH) pszString , TXTBOX_COUNT, aptlPoints);
  133.     return aptlPoints[TXTBOX_TOPRIGHT].y;
  134. }
  135.  
  136.  
  137. PMWindowPresSpace::PMWindowPresSpace(PMWin* w) : 
  138.     PMPresSpace()
  139. {
  140.        hps = WinBeginPaint (w->getHwnd(), 0L, 0L);
  141. }
  142.  
  143. PMWindowPresSpace::~PMWindowPresSpace() 
  144.     WinEndPaint (hps);
  145. }
  146.  
  147. PMMicroCachedPresSpace::PMMicroCachedPresSpace(PMWin* w) : 
  148.     PMPresSpace()
  149. {
  150.        hps = WinGetPS (w->getHwnd());
  151. }
  152.  
  153. PMMicroCachedPresSpace::~PMMicroCachedPresSpace() 
  154.     WinReleasePS (hps);
  155. }
  156.  
  157.  
  158. /////////////////////////////////////////////////////////////////////////////
  159.  
  160. PMDeviceContext::PMDeviceContext(HAB ab,HDC ihdc)
  161. {
  162.     hab=ab;
  163.     hdc=ihdc;
  164. }
  165.  
  166. PMDeviceContext::PMDeviceContext(HAB ab,LONG lType, PCSZ pszToken, LONG lCount, PDEVOPENDATA pdopData, HDC hdcComp)
  167. {
  168.     hab=ab;
  169.     hdc=DevOpenDC ( hab,lType,pszToken,lCount,pdopData,hdcComp);
  170. }
  171.  
  172. PMDeviceContext::~PMDeviceContext()
  173. {
  174.     if (hdc!=NULLHANDLE) DevCloseDC(hdc);
  175. }
  176.  
  177. HDC PMDeviceContext::open(LONG lType, PCSZ pszToken, LONG lCount, PDEVOPENDATA pdopData, HDC hdcComp)
  178. {
  179.     hdc=DevOpenDC ( hab,lType,pszToken,lCount,pdopData,hdcComp);
  180.     return hdc;
  181. }
  182.  
  183. /////////////////////////////////////////////////////////////////////////////
  184.  
  185. PMMemoryDC::PMMemoryDC(HAB hab) :
  186.     PMDeviceContext(hab) { }
  187.     
  188. PMMemoryDC::PMMemoryDC(HAB hab,LONG lCount, HDC hdcComp) :
  189.     PMDeviceContext(hab,OD_MEMORY,"*",lCount,NULL,hdcComp) 
  190. }
  191.  
  192. PMMemoryDC::~PMMemoryDC() 
  193. {
  194. }
  195.  
  196. /////////////////////////////////////////////////////////////////////////////
  197.  
  198. PMPrinterDC::PMPrinterDC(HAB ab) :
  199.     PMDeviceContext(ab) 
  200. {
  201.     driv.cb=sizeof (DRIVDATA);
  202. }
  203.  
  204. PMPrinterDC::PMPrinterDC(HAB ab,LONG lCount, PDEVOPENDATA pdopData, HDC hdcComp) :
  205.     PMDeviceContext(ab,OD_QUEUED,"*",lCount,pdopData,hdcComp) 
  206. {
  207.     driv.cb=sizeof (DRIVDATA);
  208. }
  209.  
  210. PMPrinterDC::~PMPrinterDC()
  211. {
  212. }
  213.  
  214. BOOL PMPrinterDC::getInformation(PSZ szDefPrnName,PSZ szPrnData,PDEVOPENSTRUC pdop)
  215. {
  216.     char* p;
  217.     PMIniProfile prf(HINI_PROFILE);
  218.  
  219.     // get def. printer
  220.     prf.queryString("PM_SPOOLER","PRINTER",";",szDefPrnName,33L);
  221.  
  222.     if ( (p = strchr(szDefPrnName, ';')) != NULL ) *p='\0';
  223.     if ( *szDefPrnName=='\0' ) return FALSE;
  224.  
  225.     // get def. prn information
  226.     prf.queryString("PM_SPOOLER_PRINTER",szDefPrnName,";;;;",szPrnData,256L);
  227.  
  228.     if ( (p = strchr(szPrnData, ';')) == NULL )    return FALSE;
  229.     
  230.     pdop->pszDriverName = p + 1;
  231.     
  232.     if ( (p = strchr(pdop->pszDriverName, ';')) == NULL )    return FALSE;
  233.  
  234.     pdop->pszLogAddress = p + 1;
  235.  
  236.     *(pdop->pszLogAddress + strcspn (pdop->pszLogAddress, ",;")) = '\0' ;
  237.     *(pdop->pszDriverName + strcspn (pdop->pszDriverName, ",;")) = '\0' ;
  238.     
  239.     return TRUE;    
  240. }
  241.  
  242. HDC PMPrinterDC::open()
  243. {
  244.     char* p;
  245.     if (!getInformation(achDefPrnName,achPrnData,&dop)) return DEV_ERROR;
  246.  
  247.     if ((p=strchr(dop.pszDriverName, '.')) != NULL) {
  248.         *p='\0';
  249.         strncpy (driv.szDeviceName, p + 1, sizeof(driv.szDeviceName));
  250.         dop.pdriv=&driv;
  251.     } else 
  252.         dop.pdriv = NULL;
  253.     dop.pszDataType = "PM_Q_STD";
  254.  
  255.     hdc=DevOpenDC( hab, OD_QUEUED, "*", 4L, (PDEVOPENDATA)&dop, 0L);
  256.     return hdc;
  257. }
  258.  
  259. LONG PMPrinterDC::startDoc(PSZ szDocName)
  260. {
  261.     return DevEscape(hdc,DEVESC_STARTDOC,strlen(szDocName),szDocName,NULL,NULL);
  262. }
  263.  
  264. LONG PMPrinterDC::endDoc(PSZ szDocName)
  265. {
  266.     return DevEscape(hdc,DEVESC_ENDDOC,strlen(szDocName),szDocName,NULL,NULL);
  267. }
  268.  
  269. LONG PMPrinterDC::newFrame()
  270. {
  271.     return DevEscape(hdc,DEVESC_NEWFRAME,0,NULL,NULL,NULL);
  272. }
  273.  
  274. LONG PMPrinterDC::abortDoc()
  275. {
  276.     return DevEscape(hdc,DEVESC_ABORTDOC,0,NULL,NULL,NULL);
  277. }
  278.  
  279.